FLEX/BISON : Why my rule is not regonized ?
Posted
by Natim
on Stack Overflow
See other posts from Stack Overflow
or by Natim
Published on 2010-03-09T16:02:05Z
Indexed on
2010/06/02
6:54 UTC
Read the original article
Hit count: 696
Hi,
I am trying to do a little exercice in FLEX and BISON.
Here is the code I wrote :
calc_pol.y
%{
#define YYSTYPE double
#include "calc_pol.tab.h"
#include <math.h>
#include <stdlib.h>
%}
%start line
%token NOMBRE
%token FIN
%%
line: exp '\n' { printf("\t%.2lf\n", $1); };
exp: exp exp '+' { $$ = $1 + $2 ;}
| exp exp '-' { $$ = $1 - $2 ;}
| exp exp '*' { $$ = $1 * $2 ;}
| exp exp '/' { $$ = $1 / $2 ;}
| exp exp '^' { $$ = pow($1, $2) ;}
| NOMBRE;
%%
calc_pol.l
%{
#include "calc_pol.tab.h"
#include <stdlib.h>
#include <stdio.h>
extern YYSTYPE yylval;
%}
blancs [ \t]+
chiffre [0-9]
entier [+-]?[1-9][0-9]* | 0
reel {entier}('.'{entier})?
%%
{blancs}
{reel} { yylval = atof(yytext); return NOMBRE; }
\n { return FIN; }
. { return yytext[0]; }
%%
Makefile
all: calc_pol.tab.c lex.yy.c
gcc -o calc_pol $< -ly -lfl -lm
calc_pol.tab.c: calc_pol.y
bison -d calc_pol.y
lex.yy.c: calc_pol.l
flex calc_pol.l
Do you have any idea of what's wrong ? Thanks
Edited:
The error message is
flex calc_pol.l: calc_pol.l:18: règle non reconnue
Line 18 is the line beginning with {reel}
, and the error message translates to English as "unrecognized rule".
© Stack Overflow or respective owner